package com.bootdo.lgs.combox.controller;

import com.bootdo.common.utils.K100HttpRequest;
import com.bootdo.common.utils.MD5;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Kuai {


        public static void main(String[] args) throws Exception {

//            String param ="{\"com\":\"***\",\"num\":\"***\"}";
//            String customer ="***";
//            String key = "****";

            String param ="{\"com\":\"annengwuliu\",\"num\":\"300278862051\"}";//300269633145
            String customer ="05485DC4678EE23413CEB1068883E511";
            String key = "LEARYYMZ8073";

            String sign = MD5.encode(param+key+customer);
            HashMap params = new HashMap();
            params.put("param",param);
            params.put("sign",sign);
            params.put("customer",customer);
            String resp;
            try {
                resp = new K100HttpRequest().postData("http://poll.kuaidi100.com/poll/query.do", params, "utf-8").toString();
                //String url = "http://poll.kuaidi100.com/poll/query.do";
                //String param = "cdkey=" + sn + "&password=" + key;
                //url = url + "?" + param;
//                String responseString = HttpClientUtil.getInstance().doPostRequest(url);
//                responseString = responseString.trim();
               System.out.println(resp);
               List<Map> orderList = new ArrayList<>();
                // 格式化数据
                JSONObject reslut = JSONObject.fromObject(resp);
                JSONArray kuaidiList = (JSONArray) reslut.get("data");
                if (kuaidiList != null && kuaidiList.size() > 0) {
                    for (int i = 0; i < kuaidiList.size(); i++) {
                        JSONObject jobj = JSONObject.fromObject(kuaidiList.get(i));
                        Map<Object, Object> map = new HashMap<Object, Object>();
                        map.put("time", jobj.get("ftime"));
                        map.put("context", jobj.get("context"));
                        orderList.add(map);
                    }
                }

                System.out.println(orderList);

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }


}
